<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../node_modules/vue/dist/vue.js"></script>
</head>

<body>
  <div id="app">
    <p>num<input v-model="num"/></p>
    <p><button @click="obj.b=100">修改obj的b</button></p>
    <p>a<input v-model="a"/></p>
    <p>obj:{{obj}}</p>
    <p>
      {{c1}}-{{c1}}-{{c1}}
    </p>
    <p>{{a}}</p>
  </div>
  <script>
    const vm = new Vue({
      el: "#app",
      data() {
        return {
          num: 100,
          a:1,
          obj: {
            b: 1
          }
        }
      },
      computed: {
        c1 () {
          console.log("c1")
          return this.num + 1
        }
      },
      watch: {
        // newVal:新值, oldVal：老值
        // obj (newVal, oldVal) {
        // 
        //   console.log('obj 变化了')
        // },
        obj: {
          immediate: true, // 立即执行一次。第一次执行时，oldVal是undefined, newVal就是初值
          deep:true, // 深度侦听，可以侦听到某个属性的变化
          handler (newVal, oldVal) {
            console.log('obj 变化了', newVal, oldVal)
          }
        }
      }
    })

  
  </script>
</body>

</html>